<?php
   $db = new mysqli('localhost', 'plotkinm' ,'FaceBooK', 'plotkinm_db');
        
        if(!$db) {
        
                echo 'Could not connect to the database.';
        } else {
        
                if(isset($_POST['queryString'])) {
                        $queryString = $db->real_escape_string($_POST['queryString']);
                        
                        if(strlen($queryString) >0) {

                                $query = $db->query("SELECT name FROM `states` WHERE name LIKE '$queryString%' LIMIT 10");
                                if($query) {
                                echo '<ul>';
                                        while ($result = $query ->fetch_object()) {
                                        echo '<li onClick="fill('.$result->name.');"><p>'.$result->name.'</p></li>';
                                }
                                echo '</ul>';
                                        
                                } else {
                                        echo 'OOPS we had a problem :(';
                                }
                        } else {
                                // do nothing
                        }
                } else {
                        echo '';
                }
        }
?>
